package com.redis.contrller;

import com.redis.constant.OrderMQConstants;
import com.redis.config.SendMessage;
import com.redis.enty.OrderInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/ttl")
public class SendMsgController {
    /**
     * 发送延迟消息
     */
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private SendMessage sendMessage;

    @GetMapping("/sendMsg/{message}")
    public void sendMsg(@PathVariable String message) {
        log.info("当前时间：{}，发送一条消息给两个TTL队列：{}", new Date().toString(), message);
        OrderInfo orderInfo =new OrderInfo();
        orderInfo.setId(1);
//        sendMessage.sendMqMsg(orderInfo,OrderMQConstants.CANCEL_ORDER_NORMAL_EXCHANGE, OrderMQConstants.CANCEL_ORDER_ROUTING_KEY);
//        orderInfo.setId(2);
//        sendMessage.sendMqMsg(orderInfo,OrderMQConstants.RECEIVED_ORDER_NORMAL_EXCHANGE, OrderMQConstants.RECEIVED_ORDER_ROUTING_KEY);
        sendMessage.sendMsg(OrderMQConstants.CANCEL_ORDER_EXCHANGE ,OrderMQConstants.CANCEL_ORDER_ROUTING_KEY,  message,OrderMQConstants.CANCEL_ORDER_TIME);
        log.info("当前时间：{}，发送一条消息给两个TTL队列：{}", new Date().toString(), message);
        sendMessage.sendMsg(OrderMQConstants.RECEIVED_ORDER_EXCHANGE ,OrderMQConstants.RECEIVED_ORDER_ROUTING_KEY,  message,OrderMQConstants.RECEIVED_ORDER_TIME);

    }
}
